<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body{
				background-color: transparent !important;
			}
			.footer { position: fixed; left: 0; right: 0; bottom: 45px; display:flex; }
			.footer div { width:100%; border:0px red solid; text-align: center;}
			.footer img { width:50px; margin:0 auto; }
			.footer div span { font-size:14px; color:#fff; line-height:75px;}
			.footer div p { font-size:12px; color:#fff; line-height:35px;}
			.display-none{ display:none; }
			.text-center { text-align: center !important; }
		</style>
	</head>
	<body>
		<div id="filter" style="height:100%;">
		<div id="content">
		<div class="footer">
			<div tapmode onclick="changespeaker();" id="speakerdiv">
				<span>&nbsp;</span>
				<img src="../../image/nospeaker.png" id="speakerimg" />
				<p id="speakertxt">听筒</p>
			</div>
			<div tapmode onclick="hangup();">
				<span id="calltime">00:00</span>
				<img src="../../image/refuse.png" />
				<p>挂断</p>
			</div>
			<div tapmode="btnpress" onclick="changecamera();" id="cameradiv">
				<span>&nbsp;</span>
				<img src="../../image/nocarema.png" id="cameraimg" />
				<p id="cameratxt">&nbsp;</p>
			</div>
		</div>
		</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js" ></script>
	<script type="text/javascript" src="../../script/app.js" ></script>
	<script type="text/javascript">
		var rong,mediaType;
		window.onload = function(){
			var mm = 0;
			var ss = 0;
			var str = '';
			var timer = setInterval(function(){
				str = "";
				if(++ss==60)
				{
					if(++mm==60)
					{
						mm=0;
					}
					ss=0;
				}
				str+=mm<10?"0"+mm:mm;
				str+=":";
				str+=ss<10?"0"+ss:ss;
				document.getElementById("calltime").innerHTML = str;
			},1000);
		};
		apiready = function() {
			api.parseTapmode();
			mediaType = api.pageParam.mediaType;;
			rong = api.require('rongCloud2');
			//点击空白处移除Frame
			var myDiv = document.getElementById("filter");
			myDiv.addEventListener("touchstart",function(){

			});
			var myDiv1 = document.getElementById("content");
			myDiv1.addEventListener("touchstart",function(event){
				event=event||window.event;
				event.stopPropagation();
			});
			if(mediaType == 'video') {
				$api.text($api.byId('cameratxt'),'摄像头翻转');
				$api.byId('cameraimg').src = '../../image/changecamera.png';
			}
			
		}
		function changecamera() {
			if(mediaType != 'video') {
				return false;
			}
			rong.switchCameraMode(function(ret){
			});
			toast('切换成功');
		}
		function changespeakerios() {
			rong.speakerEnabled(function(ret){
				console.log(JSON.stringify(ret));
				if(ret.speakerEnabled){
					
					rong.setSpeakerEnabled({
						speakerEnabled: false
					},function(ret){
						if(ret.status){
							toast('已启用听筒');
							$api.byId('speakerimg').src = '../../image/speaker.png';
							$api.text($api.byId('speakertxt'),'免提');
							
						}
					});
					
				}
				else
				{
					rong.setSpeakerEnabled({
						speakerEnabled: true
					},function(ret){
						if(ret.status){
							toast('已启用免提');
							$api.byId('speakerimg').src = '../../image/nospeaker.png';
							$api.text($api.byId('speakertxt'),'听筒');
						}
					});
					
				}
			});
		}
		function changespeaker() {
			if (api.systemType != "android") {
				changespeakerios();
				return;
			}
			if($api.text($api.byId('speakertxt')) == '听筒') {
				rong.setSpeakerEnabled({
					speakerEnabled: false
				},function(ret){
					
				});
				toast('已启用听筒');
				$api.byId('speakerimg').src = '../../image/speaker.png';
				$api.text($api.byId('speakertxt'),'免提');
			}
			else
			{
				rong.setSpeakerEnabled({
					speakerEnabled: true
				},function(ret){
					
				});
				toast('已启用免提');
				$api.byId('speakerimg').src = '../../image/nospeaker.png';
				$api.text($api.byId('speakertxt'),'听筒');
			}
		}
		function closeframe() {
			api.closeFrame({
				name: api.frameName
			});
		}
		function hangup() {
			//挂断
			api.stopPlay();
			rong.hangup();
			
			api.startPlay({
				path: 'widget://res/dong.wav'
			}, function(ret, err) {
				if (ret) {
					setTimeout(function(){
						closeframe();
					}, 1000);
					
				} else {
					//alert(JSON.stringify(err));
				}
			});
		}
	</script>
</html>